import java.util.*;

public class Solution966 {
    public String[] spellchecker(String[] wordlist, String[] queries) {
        Set<String> set = new HashSet<>(Arrays.asList(wordlist));
        Map<String,String> map1=new HashMap<>();
        for (String s : wordlist) {
            if (!map1.containsKey(s.toLowerCase())){
                map1.put(s.toLowerCase(),s);
            }
        }
        Map<String,String> map2=new HashMap<>();
        for (String s : wordlist) {
            String n=s.toLowerCase();
            n=n.replace("a","?");
            n=n.replace("e","?");
            n=n.replace("i","?");
            n=n.replace("o","?");
            n=n.replace("u","?");
            if (!map2.containsKey(n)){
                map2.put(n,s);
            }
        }
        String[] ans=new String[queries.length];
        for (int i=0;i<queries.length;i++){
            if (set.contains(queries[i])){
                ans[i]=queries[i];
            }else if (map1.containsKey(queries[i].toLowerCase())){
                ans[i]=map1.get(queries[i].toLowerCase());
            }else{
                String n=queries[i].toLowerCase();
                n=n.replace("a","?");
                n=n.replace("e","?");
                n=n.replace("i","?");
                n=n.replace("o","?");
                n=n.replace("u","?");
                ans[i] = map2.getOrDefault(n, "");
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Solution966().spellchecker(new String[]{"KiTe", "kite", "hare", "Hare"}, new String[]{"kite", "Kite", "KiTe", "Hare", "HARE", "Hear", "hear", "keti", "keet", "keto"})));
    }
}
